import type { ReactiverLike } from "../types";
import Key from "./key";

export function isClosed(reactiver: ReactiverLike): boolean;
export function isClosed(reactiver: ReactiverLike, error: boolean): never | boolean;
export function isClosed(reactiver: ReactiverLike, error?: boolean, errText?: string): unknown {
    if (reactiver.closed) {
        if (error) {
            throw new Error(errText || ('Reactiver Is Closed ! Name: ' + Key.findKey(reactiver.key)))
        }
        return true
    }

    return false
}